Skip to content

fix Storage of sensitive information in build artifact #6635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

odaysec
Copy link

@odaysec odaysec commented Apr 26, 2025

kitsune/webpack.common.js

Lines 110 to 112 in d7ba74f

new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env),
}),

fix the issue should avoid including all environment variables in the build artifact. Instead, we should explicitly whitelist only the environment variables that are safe and necessary for the application to function. This can be achieved by creating a new object that contains only the required variables and passing it to webpack.DefinePlugin.

In this case, we will replace the current webpack.DefinePlugin configuration to include only a specific set of environment variables, such as DEBUG or any other explicitly defined variables.

Sensitive information included in a build artifact can allow an attacker to access the sensitive information if the artifact is published. The following creates a webpack configuration that inserts all environment variables from the host into the build artifact:

const webpack = require("webpack");

module.exports = [{
    plugins: [
        new webpack.DefinePlugin({
            "process.env": JSON.stringify(process.env)
        })
    ]
}];

The environment variables might include API keys or other sensitive information, and the build-system should instead insert only the environment variables that are supposed to be public. for fixed below, where only the DEBUG environment variable is inserted into the artifact.

const webpack = require("webpack");

module.exports = [{
    plugins: [
        new webpack.DefinePlugin({
            'process.env': JSON.stringify({ DEBUG: process.env.DEBUG })
        })
    ]
}];

References

DefinePlugin API
CWE-312
CWE-315
CWE-359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant